package org.kernely.scheduling.administration;

import org.kernely.ui.mvp.IKernelyView;

import com.vaadin.terminal.Sizeable;
import com.vaadin.ui.Alignment;
import com.vaadin.ui.Button;
import com.vaadin.ui.Component;
import com.vaadin.ui.Label;
import com.vaadin.ui.NativeSelect;
import com.vaadin.ui.PopupDateField;
import com.vaadin.ui.TextField;
import com.vaadin.ui.VerticalLayout;

@SuppressWarnings("serial")
public class AddEditJobView extends VerticalLayout implements IKernelyView{
	
	private NativeSelect jobsBox;
	private TextField cronExpressionField;
	private Button validateButton;
	private PopupDateField startDateField;
	private PopupDateField endDateField;
	private Label descriptionLabel;

	
	/**
	 * AddEditUserManagementView's constructor
	 */
	public AddEditJobView(){
		this.descriptionLabel = new Label();
		this.descriptionLabel.setWidth(310, Sizeable.UNITS_PIXELS);

		this.jobsBox = new NativeSelect();
		this.jobsBox.setRequiredError("You must choose a job.");
		this.jobsBox.setWidth(310, Sizeable.UNITS_PIXELS);
		this.jobsBox.setNullSelectionAllowed(false);
		this.jobsBox.setImmediate(true);
		this.jobsBox.focus();

		this.cronExpressionField = new TextField("Cron expression");
		this.cronExpressionField.setRequired(true);
		this.cronExpressionField.setWidth(200, Sizeable.UNITS_PIXELS);
		this.cronExpressionField.setInputPrompt("Enter a cron expression");
		
		this.startDateField = new PopupDateField("Start date");
		this.startDateField.setResolution(PopupDateField.RESOLUTION_SEC);
		this.startDateField.setInputPrompt("Optional start date");
		
		this.endDateField = new PopupDateField("End date");
		this.endDateField.setResolution(PopupDateField.RESOLUTION_SEC);
		this.endDateField.setInputPrompt("Optional end date");
		
		this.validateButton = new Button();
		
		this.addComponent(jobsBox);
		this.addComponent(descriptionLabel);
		this.addComponent(cronExpressionField);
		this.addComponent(startDateField);
		this.addComponent(endDateField);
		this.addComponent(validateButton);
		
		this.setComponentAlignment(cronExpressionField, Alignment.MIDDLE_CENTER);
		this.setComponentAlignment(startDateField, Alignment.MIDDLE_CENTER);
		this.setComponentAlignment(endDateField, Alignment.MIDDLE_CENTER);
		this.setComponentAlignment(validateButton, Alignment.MIDDLE_CENTER);
		
		// Window's size
		this.setWidth(350, Sizeable.UNITS_PIXELS);
		this.setHeight(350, Sizeable.UNITS_PIXELS);
		this.setSpacing(true);
		this.setMargin(true, true, true, true);
	}

	/**
	 * Gets the jobsBox
	 * @return the jobsBox
	 */
	public NativeSelect getJobsBox() {
		return jobsBox;
	}
	
	/**
	 * Gets the cronPatternField
	 * @return the cronPatternField
	 */
	public TextField getCronExpressionField() {
		return cronExpressionField;
	}

	
	/**
	 * Gets the validateButton
	 * @return the validateButton
	 */
	public Button getValidateButton() {
		return validateButton;
	}

	
	
	
	/**
	 * Gets the descriptionLabel
	 * @return the descriptionLabel
	 */
	public Label getDescriptionLabel() {
		return descriptionLabel;
	}

	/**
	 * Gets the startDateField
	 * @return the startDateField
	 */
	public PopupDateField getStartDateField() {
		return startDateField;
	}

	/**
	 * Gets the endDateField
	 * @return the endDateField
	 */
	public PopupDateField getEndDateField() {
		return endDateField;
	}

	/**
	 * Unused method
	 */
	public Component getComponent() {
		return this;
	}
	
	
}
